package com.template.web.utils;

import com.template.web.entity.User;
import org.apache.shiro.SecurityUtils;

import java.util.Objects;
import java.util.Optional;

public class SecurityUtil {

    public static Optional<User> getCurrentUser() {
        Object principal = SecurityUtils.getSubject().getPrincipal();
        if (Objects.nonNull(principal)) {
            if (principal instanceof User) {
                return Optional.of((User) principal);
            }
        }
        return Optional.empty();
    }
}
